//
//  PayFoodKnowViewController.m
//  Menu
//
//  Created by dllo on 15/7/7.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "PayFoodKnowViewController.h"

@interface PayFoodKnowViewController ()

@end

@implementation PayFoodKnowViewController

- (void)dealloc
{
    [_knowTableView release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.frame = CGRectMake(0, 64+260*HEIGHT+40*HEIGHT, MyWidth, MyHeight-64-49-260*HEIGHT-40*HEIGHT);
    self.knowTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MyWidth, MyHeight-64-49-260*HEIGHT-40*HEIGHT) style:UITableViewStylePlain];
    self.knowTableView.backgroundColor = [UIColor whiteColor];
    self.knowTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.knowTableView.bounces = YES;
    [self.view addSubview:self.knowTableView];
    
    self.knowTableView.delegate = self;
    self.knowTableView.dataSource = self;
    [_knowTableView release];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *scienceStr = [NSString stringWithFormat:@"        %@",self.payFood.scienceNous];
    NSString *promptStr= [NSString stringWithFormat:@"        %@",self.payFood.meekPrompt];
    CGFloat oneHeight = [[self class] heightForcell:scienceStr];
    CGFloat twoHeight = [[self class] heightForcell:promptStr];
    
    return 270*WIDTH + oneHeight + twoHeight;
}


+(CGFloat)heightForcell:(NSString *)content
{
    //参数1.设置计算内容的宽和高
    //参数2.设置计算高度模式
    //参数3.设置计算字体大小属性
    //参数4.系统备用参数,设置为nil
    //其中宽度一定与显示内容的label宽度一致否则计算不准确  高度尽量大一些
    CGSize size=CGSizeMake(355*WIDTH, 10000);
    //字体大小一定与显示内容的label字体大小一致  默认是17.0
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17.0] forKey:NSFontAttributeName];
    
    CGRect frame=  [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *know = @"knowCell";
    PayFoodTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:know];
    if (cell == nil)
    {
        cell = [[PayFoodTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:know];
    }
    cell.payFoodModel = self.payFood;
    [cell.contentView sizeToFit];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}









































- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
